﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CutAways.Geometry;
using CutAways.Modeling;

namespace CutAways.Illustration
{
	[Serializable]
	class ViewpointSet : IEnumerable<Camera>
	{
		private List<Camera> viewpoints;
		private Dictionary<Camera, OcclusionGraph> graphs;

		public ViewpointSet()
		{
			this.viewpoints = new List<Camera>();
			this.graphs = new Dictionary<Camera, OcclusionGraph>();
		}

		public int Count
		{
			get { return viewpoints.Count; }
		}

		public Camera this[int index]
		{
			get { return viewpoints[index]; }
		}

		public void AddViewpoint(Model myModel, Camera viewpoint)
		{
			OcclusionGraph correspondingGraph = new OcclusionGraph(myModel, viewpoint);
			viewpoints.Add(viewpoint);
			graphs[viewpoint] = correspondingGraph;
		}

		public void RemoveViewpointAt(int index)
		{
			Camera toRemove = viewpoints[index];
			graphs.Remove(toRemove);
			viewpoints.RemoveAt(index);
		}

		public OcclusionGraph GetOcclusionGraphOf(Camera viewpoint)
		{
			return graphs[viewpoint];
		}

		#region IEnumerable<Camera> Members

		public IEnumerator<Camera> GetEnumerator()
		{
			return this.viewpoints.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return this.viewpoints.GetEnumerator();
		}

		#endregion

		public OcclusionGraph GetOcclusionGraphAt(int index)
		{
			return graphs[viewpoints[index]];
		}
	}
}
